//
// Created by Administrator on 2025/9/18.
//

#include "../Header/Clock.h"
#include<iostream>
#include<ctime>
#include<unistd.h>

Clock::Clock() {
    time_t t = time(NULL);
    tm local = *localtime(&t);
    _hour = local.tm_hour;
    _minute = local.tm_min;
    _second = local.tm_sec;
}

void Clock::run(){
    for(;;){
        tick();
        show();
    }
}

void Clock::tick(){
    sleep(1);
    if(++_second == 60){
        _second = 0;
        if(++_minute == 60){
            _minute = 0;
            if(++_hour == 24)
                _hour = 0;
        }
    }
}

void Clock::show(){
//    system("cls");
    std::cout << _hour << ":" << _minute << ":" << _second << std::endl;
}